<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-wms__spuinfo}">
      <div class="ba-operate-form">
        <el-form :model="dataForm" @keyup.enter.native="getDataList()" label-width="70px">
          <el-row :gutter="20">
            <el-col :md="6" :sm="6">
              <el-form-item label="砂芯图号">
                <el-input v-model="dataForm.spuNo" placeholder="精确匹配" maxlength="20" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="6">
              <el-form-item label="砂芯名称">
                <el-input v-model="dataForm.spuName" placeholder="模糊匹配" maxlength="20" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="9">
                  <el-form-item label="砂芯描述">
                    <el-input v-model="dataForm.spuDescription" placeholder="模糊匹配" maxlength="20" clearable></el-input>
                  </el-form-item>
                </el-col>
            <el-col :md="6" :sm="6">
              <div class="right-handle-group">
                <el-button-group>
                  <el-button @click="getDataList()" type="primary">{{ $t('query') }}</el-button>
                  <el-button @click="getReset()">{{ $t("reset") }}</el-button>
                  <el-tooltip class="item" effect="dark" content="高级搜索" placement="top-start">
                    <el-button @click="advanced = !advanced" color="#dcdfe6" icon="el-icon-search" plain></el-button>
                  </el-tooltip>
                </el-button-group>
              </div>
            </el-col>
          </el-row>
          <el-collapse-transition>
            <div v-show="advanced">
              <el-row :gutter="20">
                <el-col :md="8" :sm="12">
                  <el-form-item label="创建日期">
                    <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange"
                      range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                      :picker-options="pickerOptions">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-collapse-transition>
        </el-form>
      </div>
      <div class="ba-operate-button">
        <el-form :inline="true">
          <el-form-item>
            <el-button v-if="$hasPermission('wms:spu-info:save')" type="primary" @click="addOrUpdateHandle()">{{
              $t("add")
            }}</el-button>
          </el-form-item>
        </el-form>
      </div>

      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
        style="width: 100%" max-height="380">
        <el-table-column prop="spuId" label="id" header-align="center" align="center" sortable></el-table-column>
        <el-table-column prop="spuNo" label="砂芯图号" header-align="center" align="center" min-width="135">
        </el-table-column>
        <el-table-column prop="lotNo" label="批次" header-align="center" align="center">
        </el-table-column>
        <el-table-column prop="spuName" label="砂芯名称" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="spuDescription" label="砂芯描述" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="spuType" label="砂芯类型" header-align="center" align="center"></el-table-column>

        <el-table-column prop="contType" label="托盘类型" header-align="center" align="center" min-width="100"
          show-overflow-tooltip></el-table-column>
        <el-table-column prop="creatorName" label="创建用户" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="createDate" label="创建日期" header-align="center" align="center" min-width="155" sortable>
        </el-table-column>
        <el-table-column prop="updaterName" label="更新用户" header-align="center" align="center" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="updateDate" label="更新日期" header-align="center" align="center" min-width="155" sortable>
        </el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="80">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('wms:spu-info:update')" type="text" size="small"
              @click="addOrUpdateHandle(scope.row.spuId)">{{ $t("update") }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./spu-info-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/wms/spu-info/page",
        getDataListIsPage: true,
        exportURL: "/wms/spu-info/export",
        deleteURL: "/wms/spu-info",
        deleteIsBatch: true,
      },
      dataForm: {
        spuNo: '',
        spuName: '',
        spuDescription: '',
        spuType: '',
        status: '',
        contType: '',
        startDate: '',
        endDate: '',
      },
      //日期范围
      dateRange: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "当天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setHours(0, 0, 0);

              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          }
        ]
      },
      advanced: false, //高级搜索
    };
  },
  components: {
    AddOrUpdate,
  },
  methods: {
    //0.重置搜索框
    getReset() {
      this.dataForm = this.$options.data().dataForm;
      this.dateRange = this.$options.data().dateRange;
    },
  },
};
</script>
<style>
.el-row {
  margin-bottom: 0px;
}

.right-handle-group {
  float: right;
}
</style>
